package neusoft.edu.cn.guanshangshiguang.model;

import neusoft.edu.cn.guanshangshiguang.Listener.Listener;
import neusoft.edu.cn.guanshangshiguang.bean.User_inforBean;
import neusoft.edu.cn.guanshangshiguang.common.Common;
import neusoft.edu.cn.guanshangshiguang.service.Service;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class UserInforModel {

    private Retrofit retrofit;
    public UserInforModel(){
        retrofit = new Retrofit.Builder()
                .baseUrl("http://"+Common.IpAddress+"/literature_museum/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();
    }

    public void getResultList(String uid,final Listener Listener){

        Service service = retrofit.create(Service.class);

        Call<User_inforBean> loginCall = service.getUserInfor(uid);

        loginCall.enqueue(new Callback<User_inforBean>() {
                @Override
                public void onResponse(Call<User_inforBean> call, Response<User_inforBean> response) {
                    if(response!=null)
                        Listener.onResponse(response.body());
                    else Listener.onFail("获取个人信息失败");
                }

            @Override
            public void onFailure(Call<User_inforBean> call, Throwable t) {
                Listener.onFail(t.toString());
            }
        });
    }
}
